package com.bbird.od.finance.service.domain;

import com.alibaba.excel.EasyExcel;
import com.bbird.od.finance.service.models.TMBankFlow;
import com.bbird.od.finance.service.models.type.BankType;
import com.bbird.od.finance.service.listener.FlowExcelListener;

import java.io.File;
import java.util.List;

/**
 * @author ziyang Kuang
 * @date 2020/11/16
 * @describe
 */

public class TMReconciliationHandler extends AbstractReconciliationHandler<TMBankFlow> {

//    @Override
//    protected List<ERPFlow> analyseErpFlow(File erpFlowExcel) {
//        List<ERPFlow> erpFlows = super.analyseErpFlow(erpFlowExcel);
//
//        erpFlows.stream().filter(erpFlow ->
//                erpFlow.getHomeOrderNumber().toUpperCase().startsWith("XT-")
//        ).forEach(erpFlow -> {
//            String homeOrderNumber = erpFlow.getDescription().replaceAll("[^0-9]", "");
//            erpFlow.setHomeOrderNumber(homeOrderNumber);
//        });
//        return erpFlows;
//    }

    @Override
    List<TMBankFlow> analyseBankFlow(File bankFlowExcel) {
        FlowExcelListener<TMBankFlow> listener = new FlowExcelListener(this.getBankType(), bankFlowExcel.getName());
        EasyExcel.read(bankFlowExcel, TMBankFlow.class, listener).headRowNumber(5).sheet().doRead();
        listener.getDataList().forEach(bankFlow -> {
            String homeOrderNumber = bankFlow.getHomeOrderNumber().replace("T200P", "");
            bankFlow.setBusinessOrderNumber(homeOrderNumber);
            bankFlow.setHomeOrderNumber(homeOrderNumber);
        });
        return listener.getDataList();
    }

    @Override
    BankType getBankType() {
        return BankType.TM;
    }
}
